"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocketClientReqManager = void 0;
const Logger_1 = require("../utils/Logger");
const ProtoConfig_1 = require("../socketserver/protocol/ProtoConfig");
const ProtoUtils_1 = require("../socketserver/protocol/ProtoUtils");
const RetCodeDefine_1 = require("../../config/RetCodeDefine");
class SocketClientReqManager {
    onSocketMsg(socketMsg, client) {
        Logger_1.Logger.log("SocketClientReqManager.onSocketMsg==", socketMsg);
        if (socketMsg.protoName == ProtoConfig_1.ProtoConfig.resp_error_code) {
            this.onErrorCode(socketMsg, client);
        }
    }
    onErrorCode(socketMsg, client) {
        let respPack = ProtoUtils_1.ProtoUtils.DeserializeBinary(ProtoConfig_1.ProtoConfig.resp_error_code, socketMsg.protoData);
        let retCode = respPack.getRetcode();
        let msg = RetCodeDefine_1.RetCodeDefine.code2Msg.get(retCode);
        Logger_1.Logger.warn("onErrorCode==", client.id, retCode, msg);
    }
    createSysPack() {
        let sysPack = ProtoUtils_1.ProtoUtils.Create(ProtoConfig_1.ProtoConfig.struct_user_sys_info);
        sysPack.setOs("cc.sys.os");
        sysPack.setPlatform(1);
        sysPack.setOsmainversion("cc.sys.osMainVersion");
        sysPack.setOsversion("cc.sys.osVersion");
        sysPack.setGameversion("VersionManager.instance.nowVersion");
        return sysPack;
    }
    req_login(userName, pass, client) {
        let protoPack = ProtoUtils_1.ProtoUtils.Create(ProtoConfig_1.ProtoConfig.req_login);
        protoPack.setUsername(userName);
        protoPack.setPass(pass);
        let sysPack = this.createSysPack();
        protoPack.setSysinfo(sysPack);
        Logger_1.Logger.log("login==", protoPack);
        client.sendProto(protoPack, (socketMsg) => {
            let respPack = ProtoUtils_1.ProtoUtils.DeserializeBinary(ProtoConfig_1.ProtoConfig.resp_login, socketMsg.protoData);
            Logger_1.Logger.log("login resp=", socketMsg, respPack);
            let retCode = respPack.getRetcode();
            if (retCode == RetCodeDefine_1.RetCodeDefine.OK) {
                Logger_1.Logger.log("登录成功", client);
            }
            else {
                let msg = RetCodeDefine_1.RetCodeDefine.code2Msg.get(retCode);
                Logger_1.Logger.warn("登录失败==", retCode, msg);
            }
        });
    }
    //注册
    req_register(userName, pass, client) {
        let protoPack = ProtoUtils_1.ProtoUtils.Create(ProtoConfig_1.ProtoConfig.req_register);
        protoPack.setUsername(userName);
        protoPack.setPass(pass);
        Logger_1.Logger.log("req_register==", protoPack);
        client.sendProto(protoPack, (socketMsg) => {
            let respPack = ProtoUtils_1.ProtoUtils.DeserializeBinary(ProtoConfig_1.ProtoConfig.resp_register, socketMsg.protoData);
            Logger_1.Logger.log("req_register resp=", socketMsg, respPack);
            let retCode = respPack.getRetcode();
            if (retCode == RetCodeDefine_1.RetCodeDefine.OK) {
                Logger_1.Logger.log("注册成功", client);
            }
            else {
                let msg = RetCodeDefine_1.RetCodeDefine.code2Msg.get(retCode);
                Logger_1.Logger.warn("注册失败==", client, retCode, msg);
            }
        });
    }
}
exports.SocketClientReqManager = SocketClientReqManager;
SocketClientReqManager.instance = new SocketClientReqManager();
